from app.routes import StudentRoutes


class StudentView:
    def __init__(self):
        self.function_list = ["查看学生信息", "添加学生信息", "修改学生信息", "删除学生信息"]

    def display_menu(self):
        print("\n============== 学生成绩管理系统-学生管理 ==============")
        for idx, func in enumerate(self.function_list):
            print(f"  {idx + 1}. {func}")
        print("  5. 返回")
        print("请根据上面的选项输入数字并按回车继续...")

    def add_student(self):
        student_id = input("请输入学生学号：")
        student_name = input("请输入学生姓名：")
        student_gender = input("请输入学生性别：")
        student_clas_id = input("请输入学生专业：")
        resp = StudentRoutes.add_student(student_id,student_name,student_gender,student_clas_id)
        print(resp["message"])

    def get_students(self):
        keyword = input("请输入学生学号，回车搜索全部：")
        resp = StudentRoutes.get_by_keyword(keyword)
        print(resp["message"])
        for data in resp["data"]:
            print(data)

    def modify_student(self):
        id = input("请输入要修改学生学号：")
        new_name = input("请输入新学生姓名：")
        gender = input("请输入学生性别：")
        clas_id = input("请输入学生专业：")
        resp = StudentRoutes.modify_student(id, new_name, gender, clas_id)
        print(resp["message"])

    def delete_student(self):
        id = int(input("请输入要删除学生学号："))
        resp = StudentRoutes.delete_student(id)
        print(resp["message"])

    def run(self):
        self.display_menu()
        choice = input("请输入操作符：")
        if choice == "1":
            self.get_students()
            self.run()
        elif choice == "2":
            self.add_student()
            self.run()
        elif choice == "3":
            self.modify_student()
            self.run()
        elif choice == "4":
            self.delete_student()
            self.run()
        elif choice == "5":
            pass
        else:
            print("请输入正确的操作符")